package top.yxqz.util;

import top.yxqz.user.Student;

import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @author Mr.余
 * @date 2022/11/16
 */
public class JDBC {

    public static Connection getConnection() throws SQLException, ClassNotFoundException, IOException {
        InputStream stream = Student.class.getClassLoader().getResourceAsStream("jdbc.properties");
        Properties properties  = new Properties();
        properties.load(stream);
        String user = properties.getProperty("user");
        String url = properties.getProperty("url");
        String pwd = properties.getProperty("pwd");
        String driverClass = properties.getProperty("driverClass");
        Class.forName(driverClass);

        Connection connection = DriverManager.getConnection(url, user, pwd);
        return  connection;
    }


    public static Connection getConnection(String url,String user,String password) throws SQLException, ClassNotFoundException, IOException {
        Connection connection = DriverManager.getConnection(url, user, password);
        return  connection;
    }
}
